﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace AdoFramework
{
    public class DBConnString
    {
        public const string DBConnStringExpress =
                        @"Data Source=.\sqlexpress;Initial Catalog=" +
                        "dbname"
                        + ";" +
                        "Integrated Security=True;Asynchronous Processing=true;MultipleActiveResultSets=true";

        public const string DBConnStringMssql =
                       @"Data Source=.;Initial Catalog=" +
                       "demo" +
                       ";" +
                       "Integrated Security=True;Asynchronous Processing=true;MultipleActiveResultSets=true";

        public SqlConnection con1 = new SqlConnection(DBConnStringMssql);

        public SqlConnection con2 = new SqlConnection(DBConnStringMssql);

        public SqlConnection con3 = new SqlConnection(DBConnStringMssql);

        public void ProcessSql(string sql, SqlConnection con)
        {
            //using (con)
            {
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = sql;
                if (con.State == System.Data.ConnectionState.Closed)
                {
                    con.Open();
                }
                cmd.ExecuteNonQuery();
            }
       
        }

        public void Clean()
        {
            SqlCommand cmd = con3.CreateCommand();
            cmd.CommandText = "delete from tbluser";
            if (con3.State == System.Data.ConnectionState.Closed)
            {
                con3.Open();
            }
            cmd.ExecuteNonQuery();
        }

        public DataTable GetResult(string sql, SqlConnection con)
        {
            DataTable dt = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter(sql,con);
            sda.Fill(dt);
            return dt;
        }

    }
}
